/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package de.swta;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.PropertyModel;

/**
 *
 * @author Jan
 */
public abstract class PackageItemCheckBoxPanel extends Panel {
    AjaxCheckBox checkBox;
    MyItemPackage itemPackage;
    String itemId;

    public PackageItemCheckBoxPanel(String id, MyItemPackage itemPackage, String itemId) {
        super (id);
//        System.out.println("CHECKBOX: " + packageId + " - " + itemId);

        this.itemPackage = itemPackage;
        this.itemId = itemId;
        
        this.checkBox = new AjaxCheckBox("check", new ItemContainsModel(itemPackage, itemId)) {


            @Override
            public void onSelectionChanged() {
                System.out.println("ONSELECTION");
            }

            @Override
            protected void onSelectionChanged(Object newSelection) {
                System.out.println("ONSELECTION2");
                super.onSelectionChanged(newSelection);
            }

            @Override
            protected boolean wantOnSelectionChangedNotifications() {
                return true;
            }

            @Override
            protected void onUpdate(AjaxRequestTarget target) {
               
//                PackageItemCheckBoxPanel.this.checkBox.updateModel();
//                System.out.println("Change" + PackageItemCheckBoxPanel.this.checkBox.getDefaultModelObject().toString() + " " + PackageItemCheckBoxPanel.this.packageId + " (" + PackageItemCheckBoxPanel.this.itemId + ")");
//                PackageItemCheckBoxPanel.this.onClick(PackageItemCheckBoxPanel.this.checkBox.);
                 PackageItemCheckBoxPanel.this.checkBoxValueChanged();
                
            }
        };

        add(this.checkBox);
    }
    
    public final String getPackageID() {
        return this.itemPackage.getId();
    }
    
    public final String getItemId() {
        return this.itemId;
    }

    public abstract void checkBoxValueChanged();
}
